<!DOCTYPE html>
<html>
<head lang="en">
    <meta name="viewport" content=" initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link href="{$Think.config.RESOURCEURL}wx_assets/css/common.css{$Think.config.RESOURCE_VER}" rel="stylesheet">
    <link href="{$Think.config.RESOURCEURL}wx_assets/dist/gmu.css{$Think.config.RESOURCE_VER}" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/zepto.1.1.3.min.js{$Think.config.RESOURCE_VER}"></script>
    <script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/dist/gmu.min.js{$Think.config.RESOURCE_VER}"></script>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/zepto.alert.js{$Think.config.RESOURCE_VER}"></script>
    <script src="{$Think.config.RESOURCEURL}wx_assets/js/util.js{$Think.config.RESOURCE_VER}" type="text/javascript"></script>
    <script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/wx_share.js{$Think.config.RESOURCE_VER}"></script>
    <title>{$config.systemName}</title>
    <style>
        body{  background-color:#F0EFF4;color:#888888;font-size:14px;}
        .icon_title{
            margin:20px 0;
            text-align: center;
        }
        .icon_title>img{
            width:102px;
            height:102px;
        }
        h2{
            color:#888;
            font-size:14px;
            padding:0 10px;
            line-height: 30px;
        }
        .upload_container{
            padding:10px;
            background-color:white;
            overflow: hidden;
        }
        .upload_container .upload{
            width:104px;
            height:68px;
            position:relative;
            background-color:#F4F4F4;
            border:1px solid #CCCCCC;
            overflow:hidden;
            box-sizing:border-box;
        }
        .upload_container .upload>a{
            width:43px;
            height:43px;
            display: block;
            border:1px solid #CCCCCC;
            position:absolute;
            left:50%;
            top:50%;
            transform: translate(-50%,-50%);
            -webki-transform: translate(-50%,-50%);
        }
        .upload_container .upload>a:after{
            content:"";
            width:50%;
            display:block;
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%,-50%);
            -webkit-transform: translate(-50%,-50%);
            border-top:2px solid #DCDCDC;
        }
        .upload_container .upload>a:before{
            content:"";
            height:50%;
            display:block;
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%,-50%);
            -webkit-transform: translate(-50%,-50%);
            border-left:2px solid #DCDCDC;
        }
        .upload_container >li{
            float:left;
            margin-right:20px;
        }
        .upload_container >li>span{
            display:block;
            text-align: center;
            margin-top:5px;
        }
        .save_btn{
            padding:0 10px;
            margin:20px 0;
        }
        .save_btn>a.disabled{
            background-color:#ccc;
            color:white;
        }
        .save_btn>a{
            display:block;
            background-color:#1CACFF;
            color:white;
            border-radius:5px;
            text-align: center;
            padding:10px 0;
            font-size:16px;
        }
        .upload_container .img_container{
            border:0;
        }
        .upload_container .img_container>img{
            max-width: 100%;
            top: 50%;
            transform: translate(0,-50%);
            -webkit-transform: translate(0,-50%);
            position: absolute;
        }
    </style>
</head>
<body>
    <div class="icon_title">
        <img src="{$Think.config.RESOURCEURL}wx_assets/merchant/image/icon_company.png{$Think.config.RESOURCE_VER}"/>
    </div>
    <h2>请提交企业营业执照扫描件或照片</h2>
    <div class="upload_container">
        <if condition="$vendorInfo.busLicence neq ''">
            <div class="upload img_container">
                <img src="{$vendorInfo.busLicence}">
            </div>
            <else/>
            <div class="upload">
                <a></a>
            </div>
        </if>
    </div>
    <h2>请提交法人或经办人身份证扫描件或照片</h2>
    <ul class="upload_container">
        <li>
            <if condition="$vendorInfo.IDPositive neq ''">
                <div class="upload img_container">
                    <img src="{$vendorInfo.IDPositive}">
                </div>
                <span>（正面）</span>
                <else/>
                <div class="upload">
                    <a></a>
                </div>
                <span>（正面）</span>
            </if>

        </li>
        <li>
            <if condition="$vendorInfo.IDBack neq ''">
                <div class="upload img_container">
                    <img src="{$vendorInfo.IDBack}">
                </div>
                <span>（反面）</span>
                <else/>
                <div class="upload">
                    <a></a>
                </div>
                <span>（反面）</span>
            </if>
        </li>
    </ul>
    <div class="save_btn">
        <if condition="$config.money gt 0 and $vendorInfo.status lt 1">
            <a data-pay="1">提交认证（需支付{$config.money}元）</a>
            <elseif condition="$vendorInfo.status neq 3 and $vendorInfo.status neq 1 and $vendorInfo.status neq 2"/>
            <a data-pay="0">提交认证</a>
            <else/>
            <a class="disabled">提交认证</a>
        </if>
    </div>
</body>
<script>
    var baseUrl = '{$Think.config.SERVER_HOST}';
    var hrefPath = baseUrl+'call.html?customerId={$customerId}';
    var login = {
        init:function(){
            this._initEvent();
        },
        _initEvent:function(){
            var me = this;
            $(".upload").click(function(){
                var upload = $(this);
                wx_share.uploadImage(function(data){
                    var path = data.path;
                    if(!upload.hasClass('img_container')){
                        upload.addClass('img_container');
                        var str = '<img src="'+path+'"/>';
                        upload.find('a').remove();
                        upload.append(str);
                    }else{
                        upload.find('img').attr("src",path);
                    }

                });
            });
            $(".save_btn a").click(function(){
                if($(this).hasClass("disabled")){return;}
                me.save();
            })
        },
        save:function(){
            var me = this;
            var pay = $(".save_btn a").data("pay");
            var busLicence = $(".upload_container img:eq(0)").attr("src");
            var IDPositive = $(".upload_container img:eq(1)").attr("src");
            var IDBack = $(".upload_container img:eq(2)").attr("src");
            if(!busLicence||!IDPositive||!IDBack){
                $.util.alert("信息不完整！");
                return;
            }
            var params = {
                "busLicence":busLicence,
                "IDPositive":IDPositive,
                "IDBack":IDBack,
                "certificationType":0,
                "id":"{$vendorInfo.id}"
            };
            $.util.pageLoading.show();
            $.req.get("call.json?customerId={$customerId}&module=merchant&method=saveVerification", {
                params: params
            }, function (data) {
                if(pay==1){
                    me._initBuy();
                }else{
                    var myDate = new Date();
                    var time = myDate.getSeconds()+""+myDate.getMilliseconds();
                    location.href = '{$Think.config.SERVER_HOST}call.html?customerId={$customerId}&module=merchant&method=index&params=%7B%22v%22:'+time+'%7D';
                }
            });
        },
        _initBuy: function() {
            var me = this;
            var p = $.util.getParamAsObject();
            var customerId = $.util.getParam("customerId");
            var qid = '',miuid='';
            if(p){
                qid = p.qId||"";
                miuid = p.miUId||"";
            }
            var params = {
                "pids": "{$config.auditCost}",
                "type": "buy",
                "qId": qid,
                "miUId": miuid,
                "vId": "{$config.vId}"|| "",
                "counts": 1,
                "module":"merchant",
                "moduleId":"{$vendorInfo.id}",
                "method":"setVendorStatus"
            };
            $.req.get("call.json?customerId={$customerId}&module=product&method=preSubmitOrder", {
                params: params
            }, function (d) {
                if (d.hasOwnProperty('code')) {
                    $.util.alert(d.msg);
                    $.util.pageLoading.hide();
                    $("#BtnSave").removeClass("disabled");
                } else {
                    //调用订单提交
                    var oid = d.id;
                    me.submitOrder(oid, function () {
                        var myDate = new Date();
                        var time = myDate.getSeconds()+""+myDate.getMilliseconds();
                        location.href = '{$Think.config.SERVER_HOST}call.html?customerId={$customerId}&module=merchant&method=index&params=%7B%22v%22:'+time+'%7D';
                        return;
                    });
                }
            });
        },
        submitOrder: function(oid,callback) {
            var me = this;
            var payType="wxpay";
            var btn = $("#BtnSave");
            var params = {
                "id":oid,
                "remark":"",
                "sid": -1,
                "type":"buy",
                "phone":'{$vendorInfo.phone}',
                "fullName":'{$vendorInfo.name}',
                "address":"",
                "paytype": payType,
                "dtype": "delivery"
            };
            $.req.get("call.json?customerId={$customerId}&module=product&method=submitOrder", {
                params: params
            }, function (data) {
                if (typeof(data.code) !== "undefined") {
                    $.util.alert(data.msg);
                    return;
                }
                if (payType == "wxpay") {
                    try {
                        var price = data.price;
                        WeixinJSBridge.invoke('getBrandWCPayRequest', data.pkg, function(res) {
                            if (res.err_msg == 'get_brand_wcpay_request:ok') {
                                callback && callback();
//                                me.sendNotice(oid,callback);
                            } else {
                                if (res.err_msg == 'get_brand_wcpay_request:cancel') {
                                    $.util.pageLoading.hide();
                                    return $.util.alert("操作已取消");
                                } else if (res.err_msg == 'get_brand_wcpay_request:fail') {
                                    $.util.pageLoading.hide();
                                    return $.util.alert("网络错误发送失败，请稍后再试");
                                } else if (res.err_msg == 'access_control:not_allow' || res.err_msg == 'system:access_denied') {
                                    $.util.pageLoading.hide();
                                    return $.util.alert("商家尚未开通微信支付");
                                } else {
                                    $.util.pageLoading.hide();
                                    return $.util.alert(res.err_msg);
                                }
                            }
                        });
                    } catch (e) {
                        $(this).removeClass("disabled");
                        $.util.pageLoading.hide();
                        return $.util.alert("操作失败，请确保在微信浏览器中操作");
                    }
                }  else {
                    $(this).removeClass("disabled");
                    $.util.pageLoading.hide();
                    $.util.alert("支付方式错误");
                }
            },function(){
                $(this).removeClass("disabled");
                $.util.pageLoading.hide();
                $.util.alert("购买失败");
            });
        }
    };

    login.init();
</script>
<script>
    wx_share.init({
        "pkg":{
            "appId": '{$pkg.appId}',
            "timestamp": '{$pkg.timestamp}',
            "nonceStr": '{$pkg.nonceStr}',
            "signature": '{$pkg.signature}'
        },
        hide:1
    });
</script>
</html>